// packageJ/outArea/outArea.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    statistical:{},
    loveName:'',
    frozeLove:'',
    tabList:[
      {
        name: "全部",
        status: 0
      },
      {
        name: "进行中",
        status: 1
      },
      {
        name: "已完成",
        status: 2
      },
      {
        name: "已失效",
        status: -1
      }
    ],
    status:'',
    page:1,
    isLoadMore: true,
    totalPage: 0,
    recordList:[],
    siteName:'',
    imageUrl:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getRecordList();
  },
  ontabClick(event) {
    this.setData({
      status:event.detail?.name,
      page:1,
      isLoadMore:true
    })
    this.getRecordList();
  },
  getRecordList() {
    let query = {
      page:this.data.page,
      status:this.data.status,
      basic_info:1
    };
    let urlStr = app.getNetAddresss("plugin.love-released.frontend.team-accelerate-log.index");
    app._postNetWork({
      url: urlStr,
      data:query,
      success:  (resdata) => {
        console.log(resdata)
        let res = resdata.data;
        let basic_info = res.basic_info;
        let data = res.data;
        wx.hideLoading();
        wx.hideNavigationBarLoading();//隐藏导航条加载动画
        //停止下拉刷新
        wx.stopPullDownRefresh();
        if (res.result == 1) {
          this.data.totalPage = data.list?.last_page;
          if (!this.data.totalPage) {
            this.data.totalPage = 0;
          }
          this.setData({
            recordList: data.list.data,
            userInfo: data.member_info,
            statistical:data.statistical,
            frozeLove:Number(data.froze_love),
            loveName:basic_info.love
          })
          wx.setNavigationBarTitle({
            title: `${basic_info.love}释放`,
          })
        } else {
          this.data.page = this.data.page - 1;
          this.data.isLoadMore = false;
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  //获取更多数据
  getMoreData() {
    this.data.isLoadMore = false; // 防止多次请求分页数据
    if (this.data.page >= this.data.totalPage) {
      return;
    } else {
      this.data.page = this.data.page + 1;
      let query = {
        page:this.data.page,
        status:this.data.status,
      };
      let urlStr = app.getNetAddresss("plugin.love-released.frontend.team-accelerate-log.index");
      app._postNetWork({
        url: urlStr,
        data: query,
        success: (resdata) => {
          let res = resdata.data;
          let list = res.data.list?.data;
          if (res.result == 1) {
            this.data.isLoadMore = true;
            this.setData({
              recordList : this.data.recordList.concat(list),
            })
          } else {
            this.data.page = this.data.page - 1;
            this.isLoadMore = false;
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
          }
        },
        fail: function (res) {
          console.log(res);
        }
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    wx.showNavigationBarLoading();
     //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
     wx.showLoading({
      title: '刷新中...',
    })
    this.setData({
      status:'',
      page:1,
      isLoadMore: true,
    })
    this.getRecordList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.isLoadMore) {
      this.getMoreData();
    } else {
      console.log('没有更多了');
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  },
  onShareTimeline() {
  }
})
